package org.rohmh.answer.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.rohmh.category.domain.RohmhCategory;
import org.rohmh.comment.domain.Comment;
import org.rohmh.generic.entity.UUIDEntity;
import org.rohmh.question.domain.Question;

@Entity
@Table(name="rohmh_answer")
public class Answer extends UUIDEntity<Answer> {

    @Column(name="CONTENT", columnDefinition="TEXT", nullable = false)
    @Pattern(regexp = ".+", message = "content must not be empty!")
    private String content;

    private Integer vote; // INTEGER NOT NULL,

    private Date regDate;
    private Date modDate;

    private List<Comment> comments;
    
    private Question question;

	protected Answer() {
		// TODO Auto-generated constructor stub
	}

    @OneToMany(mappedBy="answer")
    @OrderBy("vote")
	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Integer getVote() {
		return vote;
	}

	public void setVote(Integer vote) {
		this.vote = vote;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public Date getModDate() {
		return modDate;
	}

	public void setModDate(Date modDate) {
		this.modDate = modDate;
	}

	@ManyToOne
	public Question getQuestion() {
		return question;
	}

	public void setQuestion(Question question) {
		this.question = question;
	}

}
